package com.practice.junit;
import static org.junit.Assert.*;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public class TestTimeSpan4 {
	
	private static final long dayTime = 1000 * 60 * 60 * 24;
	
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		//System.out.println("init all method...");
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
		//System.out.println("destory all method...");
	}

	@Before
	public void setUp() throws Exception {
		//System.out.println("start setUp method");
	}

	@After
	public void tearDown() throws Exception {
		//System.out.println("end tearDown method");
	}

	
	/*public void test_toString() {
		System.out.println("Test toString...");
		
		TimeSpan timeSpan = new TimeSpan();
		System.out.println(timeSpan.toString());
	}
	
	
	public void test_equals() {
		System.out.println("Test equals...");
		
		TimeSpan time = new TimeSpan();
		assertFalse(time.equals(null));
	}
	
	
	public void test_getTime() {
		System.out.println("Test getTime...");
		
		Random random = new Random();
		long time = 0;
		for (int i = 0 ; i < 100; i++) {
			time = random.nextInt();
			TimeSpan timeSpan = new TimeSpan(time);
			System.out.println(format(time, timeSpan.getTime()));
			assertEquals(time, timeSpan.getTime());
			System.out.println(timeSpan.toString());
		}
	}
	
	@Test
	public void test_add() {
		System.out.println("Test add...");
		
		Random random = new Random();
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
		
		long time = 0;
		Date date = null;
		TimeSpan timeSpan = null;
		for (int i = 0; i < 100; i++) {
			time = (long)(random.nextDouble() * dayTime * 10000) - (dayTime * 5000);
			date = new Date(time);	
			
			time = (long)(random.nextDouble() * dayTime * 1000) - (dayTime * 500);
			timeSpan = new TimeSpan(time);
			
			System.out.println(String.format("Date:   %1$s\nTimeSpan: %2$21s\nResult: %3$s\n",
					dateFormat.format(date), timeSpan.toString(),
					dateFormat.format(TimeSpan.add(date, timeSpan))));
		}
	}
	
	private String format(Object expected, Object actual) {
		String text = String.format("Expected: %1$s, Actual: %2$s",
				expected.toString(), actual.toString());
		return text;
	}*/
}
